package o;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.os.Build.VERSION;
import dalvik.system.DexFile;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class foz {
    private static final String ˋ = ("code_cache" + File.separator + "secondary-dexes");

    private static SharedPreferences ˎ(Context context) {
        return context.getSharedPreferences("multidex.version", VERSION.SDK_INT < 11 ? 0 : 4);
    }

    public static Set<String> ॱ(Context context, final String str) {
        final Set<String> hashSet = new HashSet();
        List<String> ˏ = ˏ(context);
        final CountDownLatch countDownLatch = new CountDownLatch(ˏ.size());
        for (final String str2 : ˏ) {
            e.ˏ().execute(new Runnable() {
                public void run() {
                    DexFile dexFile = null;
                    try {
                        if (str2.endsWith(".zip")) {
                            dexFile = DexFile.loadDex(str2, str2 + ".tmp", 0);
                        } else {
                            dexFile = new DexFile(str2);
                        }
                        Enumeration entries = dexFile.entries();
                        while (entries.hasMoreElements()) {
                            String str = (String) entries.nextElement();
                            if (str.startsWith(str)) {
                                hashSet.add(str);
                            }
                        }
                        if (dexFile != null) {
                            try {
                                dexFile.close();
                            } catch (Throwable th) {
                            }
                        }
                        countDownLatch.countDown();
                        return;
                    } catch (Throwable th2) {
                    }
                    countDownLatch.countDown();
                }
            });
        }
        countDownLatch.await();
        fmq.ॱ("Filter " + hashSet.size() + " classes by packageName <" + str + ">");
        return hashSet;
    }

    public static List<String> ˏ(Context context) {
        ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0);
        File file = new File(applicationInfo.sourceDir);
        List<String> arrayList = new ArrayList();
        arrayList.add(applicationInfo.sourceDir);
        String str = file.getName() + ".classes";
        if (!ॱ()) {
            int i = ˎ(context).getInt("dex.number", 1);
            File file2 = new File(applicationInfo.dataDir, ˋ);
            int i2 = 2;
            while (i2 <= i) {
                File file3 = new File(file2, str + i2 + ".zip");
                if (file3.isFile()) {
                    arrayList.add(file3.getAbsolutePath());
                    i2++;
                } else {
                    throw new IOException("Missing extracted secondary dex file '" + file3.getPath() + "'");
                }
            }
        }
        if (fkv.ˏ()) {
            arrayList.addAll(ˋ(applicationInfo));
        }
        return arrayList;
    }

    private static List<String> ˋ(ApplicationInfo applicationInfo) {
        List<String> arrayList = new ArrayList();
        if (VERSION.SDK_INT < 21 || applicationInfo.splitSourceDirs == null) {
            try {
                File file = new File((String) Class.forName("com.android.tools.fd.runtime.Paths").getMethod("getDexFileDirectory", new Class[]{String.class}).invoke(null, new Object[]{applicationInfo.packageName}));
                if (file.exists() && file.isDirectory()) {
                    for (File file2 : file.listFiles()) {
                        if (file2 != null && file2.exists() && file2.isFile() && file2.getName().endsWith(".dex")) {
                            arrayList.add(file2.getAbsolutePath());
                        }
                    }
                    fmq.ॱ("Found InstantRun support");
                }
            } catch (Exception e) {
                fmq.ˎ("InstantRun support error, " + e.getMessage());
            }
        } else {
            arrayList.addAll(Arrays.asList(applicationInfo.splitSourceDirs));
            fmq.ॱ("Found InstantRun support");
        }
        return arrayList;
    }

    private static boolean ॱ() {
        boolean z = false;
        boolean z2 = true;
        String str = null;
        String str2;
        try {
            if (ˊ()) {
                str = "'YunOS'";
                try {
                    if (Integer.valueOf(System.getProperty("ro.build.version.sdk")).intValue() < 21) {
                        z2 = false;
                    }
                    z = z2;
                    str2 = str;
                } catch (Exception e) {
                    str2 = str;
                }
                fmq.ˊ("VM with name " + str2 + (z ? " has multidex support" : " does not have multidex support"));
                return z;
            }
            str = "'Android'";
            CharSequence property = System.getProperty("java.vm.version");
            if (property != null) {
                Matcher matcher = Pattern.compile("(\\d+)\\.(\\d+)(\\.\\d+)?").matcher(property);
                if (matcher.matches()) {
                    try {
                        int parseInt = Integer.parseInt(matcher.group(1));
                        int parseInt2 = Integer.parseInt(matcher.group(2));
                        if (parseInt > 2 || (parseInt == 2 && parseInt2 >= 1)) {
                            z = true;
                        }
                        str2 = str;
                    } catch (NumberFormatException e2) {
                        str2 = str;
                    }
                    if (z) {
                    }
                    fmq.ˊ("VM with name " + str2 + (z ? " has multidex support" : " does not have multidex support"));
                    return z;
                }
            }
            str2 = str;
            if (z) {
            }
            fmq.ˊ("VM with name " + str2 + (z ? " has multidex support" : " does not have multidex support"));
            return z;
        } catch (Exception e3) {
            str2 = str;
        }
    }

    private static boolean ˊ() {
        try {
            String property = System.getProperty("ro.yunos.version");
            String property2 = System.getProperty("java.vm.name");
            if ((property2 == null || !property2.toLowerCase().contains("lemur")) && (property == null || property.trim().length() <= 0)) {
                return false;
            }
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}
